/*
//
//              INTEL CORPORATION PROPRIETARY INFORMATION
//  This software is supplied under the terms of a license  agreement or
//  nondisclosure agreement with Intel Corporation and may not be copied
//  or disclosed except in  accordance  with the terms of that agreement.
//    Copyright (c) 2007-2008 Intel Corporation. All Rights Reserved.
//
//
*/

#include "umc_defs.h"
#if defined(UMC_ENABLE_AVS_VIDEO_ENCODER)

#include "umc_avs_enc_compressor.h"
#include "umc_avs_sequence_header.h"

namespace UMC
{

AVSCompressor::AVSCompressor(void)
{
    m_extraBitSize = 0;
    m_maxMbBitSize = 100;

} // AVSCompressor::AVSCompressor(void)

AVSCompressor::~AVSCompressor(void)
{

} // AVSCompressor::~AVSCompressor(void)

void AVSCompressor::PrepareDisassembling(void)
{

} // void AVSCompressor::PrepareDisassembling(void)

void AVSCompressor::CopyEncoderParams(BaseCodecParams* pCodecParams)
{
    m_pAVSCompressorParams = DynamicCast<AVSVideoEncoderParams> (pCodecParams);
} // void AVSCompressor::CopyEncoderParams(BaseCodecParams* pCodecParams)

void AVSCompressor::AdvanceDisassembling(void)
{
    // update plane pointers
    if (1 == m_disCtx.m_pSeqHeader->sample_precission)
    {
        // advance luminance pointer
        m_disCtx.m_pSrcPlanes8u[0] += 16;

        // advance chrominance pointer
        m_disCtx.m_pSrcPlanes8u[1] += 8;
        m_disCtx.m_pSrcPlanes8u[2] += 8;
    }

    // update macroblock position
    m_disCtx.MbX += 1;

} // void AVSCompressor::AdvanceDisassembling(void)

void AVSCompressor::FinalizeDisassembling(void)
{
    // update variables
    m_disCtx.MbIndex += m_disCtx.MbWidth;
    m_disCtx.m_pMBInfo += m_disCtx.MbWidth;
    m_disCtx.m_pCoeffs = m_pWriteCoeffs;
    m_disCtx.MbX = 0;
    m_disCtx.MbY = m_disCtx.MbY + 1;

    // update pointers to the video planes
    if (1 == m_disCtx.m_pSeqHeader->sample_precission)
    {
        Ipp32s iPitch = m_disCtx.m_iPitch;

        m_disCtx.m_pSrcPlanes8u[0] = m_disCtx.m_pSrcPlanes8u[0] -
                                     m_disCtx.MbWidth * 16 +
                                     iPitch * 16;
        if (AVS_CHROMA_420_FORMAT == m_disCtx.m_pSeqHeader->chroma_format)
        {
            m_disCtx.m_pSrcPlanes8u[1] = m_disCtx.m_pSrcPlanes8u[1] -
                                         m_disCtx.MbWidth * 8 +
                                         iPitch * 8;
            m_disCtx.m_pSrcPlanes8u[2] = m_disCtx.m_pSrcPlanes8u[2] -
                                         m_disCtx.MbWidth * 8 +
                                         iPitch * 8;
        }
        else
        {
            m_disCtx.m_pSrcPlanes8u[1] = m_disCtx.m_pSrcPlanes8u[1] -
                                         m_disCtx.MbWidth * 8 +
                                         iPitch * 16;
            m_disCtx.m_pSrcPlanes8u[2] = m_disCtx.m_pSrcPlanes8u[2] -
                                         m_disCtx.MbWidth * 8 +
                                         iPitch * 16;
        }
    }

} // void AVSCompressor::FinalizeDisassembling(void)

} // namespace UMC

#endif // defined(UMC_ENABLE_AVS_VIDEO_ENCODER)
